<div class="layui-card">

  <div class="layui-card-body">
	  <div class="layui-row layui-form" id="form">
		 <div class="layui-col-lg2 layui-col-xs6">
			 <input type="text" name="keyword" placeholder="请输入关键词" autocomplete="off" class="layui-input">
		</div>
    <div class="layui-col-lg1 layui-col-xs3">
      <select name="cat_id">
          <option value="">分类</option>
          <?php foreach($cat as $k => $v):?>
              <option value="<?=$v['id']?>"><?php for($i=2;$i<=$v['depath'];$i++):?>&nbsp;&nbsp;&nbsp;&nbsp;<?php endfor;?>-|<?=$v['cat_title']?></option>
          <?php endforeach;?>
      </select>
    </div>
		<div class="layui-col-lg1 layui-col-xs1">
		  <button class="layui-btn layui-btn-normal" onclick="search()">搜索</button>
		</div>
	  </div>
	  <div class="layui-row">
			  <table class="layui-hide" lay-filter="table" id="table"></table>
	  </div>
  </div>

</div>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="sure">选择</a>
  <!-- <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a> -->
  <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
</script>
<script>
layui.use(['table','form','larry'], function(){
    var form = layui.form;
    var table = layui.table;
    var $ = layui.$;
    var larry = layui.larry;
    form.render('select');
    search = function(){
        var url = "/ordergoods/cgoods";
        var data = $("#form").find("[name]");
        var where = {};
        data.each(function(i,e){
            where[$(e).attr('name')] = $(e).val();
        });
        table.render({
            elem: '#table'
            ,url:url
            ,where:where
            ,method:'post'
            ,cellMinWidth:100
            ,page: true
            ,cols: [[
                // {type:'checkbox'},
                // {field:'id', title: 'ID',width:80, sort: true,title:'ID'},
                {field:'ptitle', title: '产品分类'}
                ,{field:'title', title: '产品标题'}
                ,{field:'money', title: '参考价格'}
                ,{field:'status', title: '状态'}
                ,{field:'sort',  title: '排序',edit: 'text'}
                ,{field:'create_time', title: '时间'}
                ,{field:'action', title: '操作',width:178, align:'center', toolbar: '#barDemo',fixed:"right",}
            ]]
        });
    };
    search();
      //监听工具条
      table.on('tool(table)', function(obj){
        var data = obj.data;
        if(obj.event === 'edit'){
          layer.open({
              title:'编辑',
              type:2,
              area: ['100%', '100%'],
              content:'/Goods/edit?id='+data.id
          });
        } else if(obj.event === 'del'){
          layer.confirm('确认要删除吗?', function(index){
            $.ajax({
                url:"/Goods/del",
                method:"post",
                dataType:"json",
                data:{id:data.id},
                success:function(res){
                    my.action(res);
                    layer.close(index);
                }
            });
          });
        }else if(obj.event === 'sure'){
          parent.cgoods(data);
        }
      });
      //监听编辑框
      table.on('edit(table)', function(obj){
          var data = {};
              data['table'] = 'Goods';
              data['id'] = obj.data.id;
              data['field'] = obj.field;
              data['value'] = obj.value;
          $.ajax({
              url:'/com/edit',
              method:'post',
              dataType:'json',
              data:data,
              success:function(res){
                  my.action(res);
              }
          });
      });
});
</script>
